package com.zilue.payment.gateway.method.order;

import com.zilue.payment.gateway.domain.CorpDO;
import com.zilue.payment.gateway.exception.BizManagerException;
import com.zilue.payment.gateway.manage.CancleManager;
import com.zilue.payment.gateway.method.BaseMethod;
import com.zilue.payment.gateway.paramter.BaseParameter;
import com.zilue.payment.gateway.reurndata.PublicReturn;
import com.zilue.payment.gateway.reurndata.enums.RequestStatusEnum;
import com.zilue.payment.gateway.reurndata.order.CancleReturn;
import com.zilue.payment.gateway.paramter.order.CancleParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zilue on 2017/4/20.
 */
@Service("hfpay.trade.order.cancel")
public class Cancel implements BaseMethod {

    @Autowired
    private CancleManager cancleManager;

    @Override
    public PublicReturn doMethod(CorpDO corpDO, BaseParameter baseParameter) {
        try {
            CancleParameter cancleParameter = (CancleParameter) baseParameter;
            return cancleManager.cancleOrder(corpDO, cancleParameter);
        } catch (BizManagerException exception) {
            CancleReturn cancleReturn = new CancleReturn(RequestStatusEnum.RequestSuccess);
            cancleReturn.setBusinessStatus(exception.getBusinessStatusEnum());
            cancleReturn.appendSub_msg(exception.getAppendMsg());
            return cancleReturn;
        }
    }

    @Override
    public Class<? extends BaseParameter> paramterClass() {
        return CancleParameter.class;
    }
}
